import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path:'/login',
    name:'login',
    component: ()=>import('../views/Login.vue')
  },
  {
    path:'/',
    component:()=>import('../components/Layout.vue'),
    redirect:'/index',
    children:[
      {
        path:'index',
        component:()=>import('../views/Index.vue')
      },
      {
        path:'contribute',
        component:()=>import('../views/Contribute.vue')
      },
      {
        path:'nodes',
        component:()=>import('../views/Nodes.vue')
      },
      {
        path:'chain',
        component:()=>import('../views/Chain.vue')
      },
      {
        path:'ntfs',
        component:()=>import('../views/NTFS.vue')
      }
    ]
  }
]

//第一步：将原始的push保存一份
const originPush=VueRouter.prototype.push
const originReplace=VueRouter.prototype.replace
VueRouter.prototype.push = function push(location) {
  return originPush.call(this, location).catch(err => err)
}

VueRouter.prototype.replace = function replace(location) {
  return originReplace.call(this, location).catch(err => err);
};


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
